package klassisch;

public class HillClimbing_eugen extends Algo {
	
	
	public HillClimbing_eugen(int grad, int maxRunden) {
		super(grad, maxRunden);
	}

	public void optimieren() {
		double arrVn[] = new double[arrBest.length];
		double arrVCurrent[] = new double[arrBest.length];

		double fitnessN;
		double fitnessC;

		boolean local;
		for (int i = 0; i < maxRunden; i++) {
			init(arrVCurrent);
			fitnessC = eval(arrVCurrent);
			
			
			System.out.println("FitC " +fitnessC +  " \t \t best " + fitnessBest);
			System.out.println(wz(arrVCurrent));
		
			do {
				local = false; 
				erzeugeNachbarn(arrVn, arrVCurrent);
				fitnessN = eval(arrVn);
				System.out.println("FitN " + fitnessN);
				//System.out.println(wz(arrVn));

				if (fitnessN < fitnessC) {
					arrVCurrent = arrVn.clone();
					fitnessC = fitnessN;
					System.out.println(" ** Verbesserung -- innere Schleife wird verlassen **");
				} else {
					local = true;
				}
				aufwand++;
			} while (local);
			
			if (fitnessBest > fitnessC) {
				arrBest = arrVn.clone();
				fitnessBest = fitnessC;
			} 
			aufwand++;
		}
	}
	
	public void erzeugeNachbarn(double vn[], double vcurrent[])
	{
		for (int i = 0; i < vn.length; i++) {		
			vn[i] = vcurrent[i] + r.nextGaussian();  // ... hat dem grams nicht gefallen
		} 
		
	}
	
	public static void main(String[] args) {
		
	/*	HillClimbing_eugen hill = new HillClimbing_eugen(2,100);
		hill.optimieren();
		hill.ergebnisAusgabe();
		*/
		HillClimbing_eugen hill2 = new HillClimbing_eugen(4,1000);
		hill2.optimieren();
		hill2.ergebnisAusgabe();
		/* zum Vergleich Grad 2  
		 * Mutation Selection: 
			Fitness: 0,1419
			Aufwand: 1454
		 */
	}

}
